package ejemplo;

import java.io.*;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.regex.Pattern;

public class Menu extends HttpServlet {
   
 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {} 

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
     ServletContext context = getServletContext();
     InputStream header = context.getResourceAsStream("/header.xhtml");
     InputStream menu = context.getResourceAsStream("/menu.xhtml");
     response.setContentType("text/html;charset=UTF-8");
     PrintWriter out = response.getWriter();
     if (header != null) {
       InputStreamReader isr = new InputStreamReader(header);
       BufferedReader reader = new BufferedReader(isr);
       String line ="";
       while ((line = reader.readLine()) != null){
         if(Pattern.matches(".*OPER.*", line))
           out.print(line.replaceFirst("OPER", "Indique la operacion que desea realizar"));
         else out.print(line);
       } //end while
     } //endif header

     if (menu != null) {
       InputStreamReader isr = new InputStreamReader(menu);
       BufferedReader reader = new BufferedReader(isr);
       String line ="";
       while ((line = reader.readLine()) != null)
         out.print(line);
     } //endif
  }

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException{ doGet(request, response); }

  @Override
  public String getServletInfo(){ return "Short description"; }
}
